#ifndef ___GraphCutSegmentLazy__
#define ___GraphCutSegmentLazy__
#include <iostream>
#include <fstream>
#include <opencv2/opencv.hpp>
#include "Globle.h"
#include "block.h"
#include "sPoint.h"
#include <set>
#include "graph.h"
#include <string.h>
#include <vector> 
#include <sys/timeb.h>
#include "mLinkList.h"
using namespace std;
#define ___PRINTF_TIME__
#define __EIGHT__
class GraphCutSegmentLazy
{



public:
	GraphCutSegmentLazy(IplImage* pImg,set<sPoint> *objPt,set<sPoint> *bacPt);

	~GraphCutSegmentLazy(void);
	IplImage* graphcut();
	void computeNeighbor();
	void computeNeighbor1();
	void watershed();
private:	
	
	void computeNeighbor_Array();
	void makeGraph(double colorCumulativeVariance);	
	void makeGraph1(double colorCumulativeVariance);	
	void computeMeanColor();
	double GetColorCumulativeVarivance();
	int Round(double value);
	void computeFBLabels();
	bool findValVec(set<int> labels,int i);
	double minVecD(vector<rgb> fClusters,rgb regionMeanColor);
	double diffVec(rgb color1,rgb color2);
	IplImage* segmentImage();
	void TextureClusters(double ** distribution);
	void computeClusters();

	void DrawContourInOriginalPicture(IplImage* pSrc,IplImage* pSrc1,IplImage* pGray);
	void GetMaxContourArea(IplImage* pGray);
	void adjustLabels();
	void computeTextureImageByULBP(IplImage *pGray, IplImage *pTextureImg);
	void GetTextureImageBYLBP(IplImage* pGray);
	void printImage(IplImage *pImg, const char* str);
	void getULBPDistribution(IplImage *pMarked,IplImage* pTextureImage, double** distribution,int length);
	double computeTextureDistance(double array1[],double array2[],int length);
	double GetMinTextureDistance(vector<textureFeature> textureArr,double texture[10]);
	void DrawContour(IplImage *pSrc, IplImage *pBinaryImg);
	IplImage* pSrc;
	IplImage* pMarkers;
	IplImage* pWshed;
	set<sPoint> *objectSeedPt,*backgroundSeedPt;
	int numLabels;
	Graph *graph;
	rgb* sumColor;
	vector<rgb> meanColor;
	//int numLabels;
	int* pNeighborArray;
    vector< set<int> > neighbors;
	mLinkList* mNeighbors;
	Graph::node_id *nodes;

	set<int> *pIter;
	set<int> *qIter;
	set<int> fLabels;
	set<int> bLabels;
	double LAMBDA;

	vector<int> unExistedLabels;
	//vector<set<int>::iterator> neighbors;
	vector<rgb> fClustersColor,bClustersColor;
	vector<textureFeature> fClusterTexture,bClusterTexture;
	//set
};			  
#endif
